package com.byxm.wlgw.service;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import com.byxm.wlgw.bean.Splb_sBean;
import com.byxm.wlgw.common.DataBaseAccess;
import com.byxm.wlgw.query.Splb_sQuery;

public class Splb_sService {
	/**
	 * 
	 * 获取商品类别名    跑步鞋 篮球鞋 之类的
	 * @return
	 * @throws Exception
	 */
	Splb_sQuery splb_sQuery=new Splb_sQuery("splb_s");
	
	public List<Splb_sBean> getSplb_s(int splbfid) throws Exception{
		String sql = splb_sQuery.getSplb_sSql(splbfid);
		DataBaseAccess dba=null;
		List<Splb_sBean> list=new ArrayList<Splb_sBean>();
		
		try {
			dba = new DataBaseAccess();
			ResultSet rs = dba.executeQuery(sql);
			while (rs.next()) {	
				Splb_sBean splb_s=new Splb_sBean();
				splb_s.setSplbsid(rs.getInt("splbsid"));
				splb_s.setSplbm(rs.getString("splbm"));
				splb_s.setSplbfid(rs.getInt("splbfid"));
				splb_s.setPx(rs.getInt("px"));
				list.add(splb_s);
				}
			rs.close();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			dba.releaseConnect();
		}
		return list;
	}
	/**
	 * 保存
	 * @param bean
	 * @return
	 * @throws Exception 
	 */
	public boolean saveSplbs(Splb_sBean bean) throws Exception{
		DataBaseAccess dba=null;
		PreparedStatement ps=null;
		int iFlag=0;
		try {
			dba = new DataBaseAccess();
		    ps=dba.getPstmt(splb_sQuery.saveSplb_Sql());
		    ps.setString(1,bean.getSplbm());
		    ps.setInt(2,bean.getSplbfid());
		    ps.setInt(3,bean.getPx());
		    iFlag=ps.executeUpdate();
		    dba.commit();
		    ps.close();
		} catch (Exception e) {
			dba.rollback();
			e.printStackTrace();
		}finally{
			dba.releaseConnect();
		}
		if(iFlag>0){
			return true;
		}else{
			return false;
		}
	}
	/**
	 * 删除
	 * @throws Exception 
	 */
	public boolean deleteSplbs(int splbsid) throws Exception{
		DataBaseAccess dba=null;
		PreparedStatement ps=null;
		int iFlag=0;
		try {
			dba=new DataBaseAccess();
			ps=dba.getPstmt(splb_sQuery.deleteByField("splbsid"));
			ps.setInt(1, splbsid);
			iFlag=ps.executeUpdate();
			dba.commit();
			ps.close();
		} catch (Exception e) {
			dba.rollback();
			e.printStackTrace();
		}finally{
			dba.releaseConnect();
		}
		if(iFlag>0){
			return true;
		}else{
			return false;
		}
	}
}
